<template>
  <div class="layoutCon">
      <service-header :tab="1"></service-header>
      <div class="breadcrumb">
        <router-link class="home" to="/"></router-link> > <router-link to="/service">고객센터</router-link> > 공지사항
      </div>
      <div class="comList" v-loading="pageConfig.loading&&pageConfig.page==1">
        <ul v-if="noticeList.length">
          <li v-for="(item,index) in noticeList" :key="index">
            <span><em>공지사항</em>{{item.updated_at}}</span>
            <router-link :to="'/service/noticeView?id='+item.id">
              <strong>{{item.title}}</strong>
            </router-link>
          </li>          
        </ul>
        <div class="notData" v-if="!pageConfig.loading&&noticeList.length==0">데이터 없음</div>
      </div>
      <div class="loadMore" v-if="!pageConfig.isAll">
        <el-button type="primary" :loading="pageConfig.loading" @click="loadMore" class="btnMore">더보기</el-button>
      </div>
  </div>
</template>

<script>
import { mapState, mapActions } from "vuex";
import { announcementList } from '@/api';
import serviceHeader from '@/components/serviceHeader'

export default {
  name:'',
  components:{serviceHeader},
  props:[],
  data(){
    return {
      pageConfig:{
        page:1,
        per:10,
        loading:true,
        isAll:true
      },
      noticeList:[]
    }
  },
  computed:{},
  created(){
    this.getList();
  },
  mounted(){},
  methods:{
    async getList(){
      this.pageConfig.loading=true;
      let res = await announcementList({page:this.pageConfig.page,per:this.pageConfig.per});
          if (res.code == 200) {
            this.pageConfig.page+=1;
            let _arry=res.data.data;
              if(_arry.length){
                _arry.forEach((o)=>{
                  o.isOpen=false;
                })
                this.noticeList=this.noticeList.concat(_arry);
              }
            !res.data.next_page_url?(this.pageConfig.isAll=true):(this.pageConfig.isAll=false);
            this.pageConfig.loading=false;            
          }else{
            this.pageConfig.loading=false;  
          }
    },
    loadMore(){
      !this.pageConfig.loading&&this.getList();
    },
  },
  watch:{}
}
</script>
<style lang="scss" scoped>
  @import "@/assets/styles/service.scss";
</style>